﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/AdminDefault.Master"
  AutoEventWireup="true" CodeBehind="SurveyPage.aspx.cs" Inherits="NguyenHoa.Web.Admin.SurveyPage" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div style="float: left; padding-top: 3px;">
    <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Strings, Language %>"></asp:Literal>
    :
  </div>
  <div style="float: left; padding-left: 3px;">
    <dxe:ASPxComboBox ID="cbxLanguage" ClientInstanceName="cbxLanguage" runat="server"
      DataSourceID="xdsLanguage" TextField="Value"
      ValueField="Id" ValueType="System.Int32" OnDataBound="cbxLanguage_DataBound">
      <ButtonStyle Width="11px">
      </ButtonStyle>
      <ValidationSettings>
        <ErrorImage Height="14px" Width="14px" />
      </ValidationSettings>
      <ClientSideEvents SelectedIndexChanged="function(s,e){oncbxLanguage_SelectedIndexChanged(s,e);}" />
    </dxe:ASPxComboBox>
  </div>
  <div style="clear: both; padding-top: 20px;">
    <dxwgv:ASPxGridView ID="gvChoice" ClientInstanceName="gvChoice" runat="server" AutoGenerateColumns="False"
      KeyFieldName="ID" Width="550px" OnCustomCallback="gvChoice_CustomCallback" OnCustomJSProperties="gvChoice_CustomJSProperties">
      <Templates>
        <DataRow>
          <table width="100%" class="survey" cellpadding="0" cellspacing="0">
            <tr class="survey_question">
              <td style="width: 120px;">
                <asp:Literal ID="Literal2" runat="server" Text="<%$Resources:Strings, Question %>"></asp:Literal>
                :
              </td>
              <td colspan="2">
                <%#Eval("Question") %>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Literal ID="Literal3" runat="server" Text="<%$Resources:Strings, QuestionType %>"></asp:Literal>
              </td>
              <td style="width: 200px;">
                <%#Eval("DisplayType")%>
              </td>
              <td>
                <div style="float: left;">
                  <%#Eval("ShowOnHome") %>
                </div>
                <div style="float: right; padding-top: 3px;">
                  <img src="../images/edit.png" alt="" style="cursor: pointer;" onclick="onEdit(<%#Eval("Id") %>, '<%#ParseHtml(Eval("Question")) %>', '<%#Eval("Type") %>', '<%#Eval("LanguageId") %>')" />
                  <img src="../images/delete.png" alt="" style="cursor: pointer;" onclick="onDelete(<%#Eval("Id") %>)" />
                </div>
              </td>
            </tr>
            <%#Eval("SurveyResult")%>
          </table>
        </DataRow>
      </Templates>
      <SettingsPager Mode="ShowAllRecords">
      </SettingsPager>
      <Images>
        <CollapsedButton Height="12px" Width="11px" />
        <DetailCollapsedButton Height="9px" Width="9px" />
        <HeaderFilter Height="18px"
          Width="18px" />
        <HeaderActiveFilter Height="18px"
          Width="18px" />
        <FilterRowButton Height="13px" Width="13px" />
        <CustomizationWindowClose Height="17px" Width="17px" />
        <PopupEditFormWindowClose Height="17px" Width="17px" />
        <FilterBuilderClose Height="17px" Width="17px" />
      </Images>
      <Columns>
        <dxwgv:GridViewDataTextColumn FieldName="Name" VisibleIndex="0" CellStyle-CssClass="CommonFont"
          Width="50%">
          <CellStyle CssClass="CommonFont">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Value" VisibleIndex="1" Width="50px" CellStyle-CssClass="CommonFont">
          <CellStyle CssClass="CommonFont">
            <Paddings PaddingLeft="20px" />
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Question" Visible="False" VisibleIndex="2">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="SurveyId" Visible="False" VisibleIndex="2">
        </dxwgv:GridViewDataTextColumn>
      </Columns>
      <Settings ShowColumnHeaders="False" />
      <StylesEditors>
        <ProgressBar Height="25px">
        </ProgressBar>
      </StylesEditors>
      <ClientSideEvents EndCallback="function(s,e){ongvChoice_EndCallback(s,e);}" />
    </dxwgv:ASPxGridView>
  </div>
  <div style="padding-top: 5px;">
    <dxe:ASPxButton ID="ASPxButton1" runat="server" Text="<%$ Resources:Strings, Add %>"
      AutoPostBack="False">
      <ClientSideEvents Click="function(s,e){onAdd();}" />
    </dxe:ASPxButton>
  </div>
  <asp:XmlDataSource ID="xdsLanguage" runat="server" DataFile="~/App_Data/Status.xml"
    XPath="Items/LanguageDisplay/Status"></asp:XmlDataSource>
  <asp:XmlDataSource ID="xdsType" runat="server" DataFile="~/App_Data/Status.xml" XPath="Items/SurveyType/Status">
  </asp:XmlDataSource>
  <div>
    <dxpc:ASPxPopupControl ID="pcEdit" ClientInstanceName="pcEdit" runat="server"
      Width="500px" Modal="True" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
      CloseAction="CloseButton" HeaderText="<%$ Resources:Strings, Info %>" 
      AllowDragging="True">
      <SizeGripImage Height="12px" Width="12px" />
      <ContentCollection>
        <dxpc:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
          <div style="padding-bottom: 10px;">
            <dxe:ASPxLabel ID="lblError" ClientInstanceName="lblError" runat="server" ForeColor="Red">
            </dxe:ASPxLabel>
          </div>
          <table width="100%">
            <tr>
              <td>
                <asp:Literal ID="Literal4" runat="server" Text="<%$Resources:Strings, QuestionType %>"></asp:Literal>
                :
              </td>
              <td>
                <dxe:ASPxComboBox ID="cbxType" runat="server" ClientInstanceName="cbxType" 
                  DataSourceID="xdsType" OnDataBound="cbxType_DataBound" TextField="Value"
                  ValueField="Id">
                  <ButtonStyle Width="13px">
                  </ButtonStyle>
                  <ValidationSettings>
                    <ErrorImage Height="14px" Width="14px" />
                  </ValidationSettings>
                </dxe:ASPxComboBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Literal ID="Literal5" runat="server" Text="<%$ Resources:Strings, Language %>"></asp:Literal>
                :
              </td>
              <td>
                <dxe:ASPxComboBox ID="cbxLanguageEdit" runat="server" ClientInstanceName="cbxLanguageEdit"
                  DataSourceID="xdsLanguage" TextField="Value"
                  ValueField="Id" ValueType="System.Int32">
                  <ButtonStyle Width="13px">
                  </ButtonStyle>
                  <ValidationSettings>
                    <ErrorImage Height="14px" Width="14px" />
                  </ValidationSettings>
                </dxe:ASPxComboBox>
              </td>
            </tr>
            <tr>
              <td style="padding-top: 4px;" valign="top">
                <asp:Literal ID="Literal6" runat="server" Text="<%$ Resources:Strings, Question %>"></asp:Literal>
                :
              </td>
              <td>
                <dxe:ASPxMemo ID="mmQuestion" runat="server" ClientInstanceName="mmQuestion" Height="71px"
                  Width="250px">
                </dxe:ASPxMemo>
              </td>
            </tr>
            <tr>
              <td valign="top">
                <asp:Literal ID="Literal7" runat="server" Text="<%$ Resources:Strings, Choices %>"></asp:Literal>
                :
              </td>
              <td>
                <dxwgv:ASPxGridView ID="gvEditChoice" runat="server" AutoGenerateColumns="False"
                  ClientInstanceName="gvEditChoice" OnCustomCallback="gvEditChoice_CustomCallback"
                  OnCustomJSProperties="gvEditChoice_CustomJSProperties" OnRowDeleting="gvEditChoice_RowDeleting"
                  OnRowInserting="gvEditChoice_RowInserting" OnRowUpdating="gvEditChoice_RowUpdating"
                  Width="250px" KeyFieldName="Id">
                  <ClientSideEvents EndCallback="function(s,e){ongvEditChoice_EndCallback(s,e);}" />
                  <Columns>
                    <dxwgv:GridViewCommandColumn ButtonType="Image" VisibleIndex="0" Width="60px">
                      <DeleteButton Visible="True">
                        <Image Url="~/images/delete.png" />
                      </DeleteButton>
                      <EditButton Visible="True">
                        <Image Url="~/images/edit.png" />
                      </EditButton>
                      <NewButton Visible="True">
                        <Image Url="~/images/add.png" />
                      </NewButton>
                      <CancelButton>
                        <Image Url="~/images/undo.gif" />
                      </CancelButton>
                      <UpdateButton>
                        <Image Url="~/images/save.png" />
                      </UpdateButton>
                    </dxwgv:GridViewCommandColumn>
                    <dxwgv:GridViewDataTextColumn FieldName="Name" VisibleIndex="1">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn FieldName="SurveyId" Visible="False" VisibleIndex="2">
                      <EditFormSettings Visible="False" />
                    </dxwgv:GridViewDataTextColumn>
                  </Columns>
                  <SettingsPager Mode="ShowAllRecords">
                  </SettingsPager>
                  <SettingsEditing Mode="Inline" NewItemRowPosition="Bottom" />
                  <Settings ShowColumnHeaders="False" />
                </dxwgv:ASPxGridView>
              </td>
            </tr>
            <tr>
              <td valign="top">
              </td>
              <td>
                <div style="float: left;">
                  <dxe:ASPxButton ID="ASPxButton2" runat="server" Text="<%$Resources:Strings, Save %>"
                    AutoPostBack="false">
                    <ClientSideEvents Click="function(s,e){onSave();}" />
                  </dxe:ASPxButton>
                </div>
                <div style="float: left; padding-left: 3px;">
                  <dxe:ASPxButton ID="ASPxButton3" runat="server" Text="<%$Resources:Strings, Close %>"
                    AutoPostBack="false">
                    <ClientSideEvents Click="function(s,e){pcEdit.Hide();}" />
                  </dxe:ASPxButton>
                </div>
              </td>
            </tr>
          </table>
          <asp:HiddenField ID="hfSurveyId" runat="server" />
        </dxpc:PopupControlContentControl>
      </ContentCollection>
      <CloseButtonImage Height="17px" Width="17px" />
    </dxpc:ASPxPopupControl>
  </div>

  <script language="javascript" type="text/javascript">
    function oncbxLanguage_SelectedIndexChanged(s, e) {
      gvChoice.PerformCallback();
    }

    function ongvEditChoice_EndCallback(s, e) {
      var error = s.cpInnerError;
      if (error != '') {
        var para = error.split('|');
        if (para[0] == 'Edit') {
          if (para[1] != '') {
            lblError.SetText(para[1]);
            return;
          }
          return;
        }
      }
      pcEdit.Show();
    }

    function ongvChoice_EndCallback(s, e) {
      var error = s.cpInnerError;
      if (error != '') {
        var para = error.split('|');
        if (para[0] == 'Save') {
          if (para[1] != '') {
            if (para[1] == 'Id') {
              document.getElementById('<%=hfSurveyId.ClientID %>').value = para[2];
              pcEdit.Hide();
              alertSuccess();
              return;
            }
            lblError.SetText(para[1]);
            return;
          }
          return;
        }
        else {
          alert(error);
          return;
        }
      }
    }

    function activeSurvey(id, checked) {
      gvChoice.PerformCallback('Active|' + id + '|' + checked);
    }

    function onAdd() {
      resetValue();
    }

    function onEdit(id, question, type, language) {
      document.getElementById('<%=hfSurveyId.ClientID %>').value = id;
      mmQuestion.SetText(question);
      cbxType.SetValue(type);
      cbxLanguageEdit.SetValue(language);
      gvEditChoice.PerformCallback();
      lblError.SetText('');
    }

    function onSave() {
      if (checkInput())
        gvChoice.PerformCallback('Save|');
    }

    function onDelete(id) {
      if (confirm('<%=GetGlobalResourceObject("Messages", "ERR0006") %>')) {
        gvChoice.PerformCallback('Delete|' + id);
      }
    }

    function checkInput() {
      if (mmQuestion.GetText() == '') {
        lblError.SetText('<%=String.Format(Resources.Messages.ERR0007, Resources.Strings.Question) %>');
        return false;
      }
      if (gvEditChoice.GetVisibleRowsOnPage() == 0) {
        lblError.SetText('<%=String.Format(Resources.Messages.ERR0062, Resources.Strings.Answer) %>');
        return false;
      }
      return true;
    }

    function resetValue() {
      document.getElementById('<%=hfSurveyId.ClientID %>').value = '';
      mmQuestion.SetText('');
      if (cbxType.GetItemCount() > 0)
        cbxType.SetSelectedIndex(0);
      cbxLanguageEdit.SetValue(cbxLanguage.GetValue());
      lblError.SetText('');
      gvEditChoice.PerformCallback('ClearCache|');
    }
  </script>

</asp:Content>
